package com.zx.controller;

import com.zx.pojo.User;
import com.zx.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * ExampleController
 *
 * @author
 * @since 2022-11-30
 */
@Controller
public class ExampleController {

    @Resource
    private UserService userService;

    @GetMapping("/hello/{id}")
    public String hello(Model model, HttpServletRequest request, HttpSession session, @PathVariable("id") Long usrId) {
        User user = userService.getById(usrId);
        model.addAttribute("user", user);
        request.setAttribute("usrPassword", user.getUsrPassword());
        session.setAttribute("usrRoleId", user.getUsrRoleId());
        model.addAttribute("users", userService.list());
        return "demo/hello";
    }

    @GetMapping("/layout")
    public String layout() {
        return "demo/layout";
    }

    @GetMapping("/test")
    public String test() {
        return "demo/test";
    }
}
